﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Mail;
using MySql.Data.MySqlClient;
using Could.Service;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace Could.Service.Utilitis
{
    class Cemail
    {
        public string Subject="密码恢复邮件", pstrFrom, pstrTo;
        public string Body="";
        public  Boolean SendSMTPEmail() {
            MailMessage mm = new MailMessage( pstrFrom , pstrTo);
            try
            {
                mm.Subject = Subject;
                mm.Body = Body;
                mm.SubjectEncoding = Encoding.GetEncoding("gb2312");
                mm.BodyEncoding = Encoding.GetEncoding("gb2312");
                mm.IsBodyHtml = true;
                mm.Priority = MailPriority.Normal;

                SmtpClient sc = new SmtpClient();
                sc.Host = "smtp.gmail.com";
                sc.UseDefaultCredentials = false;
                sc.EnableSsl = true;
                sc.Credentials = new System.Net.NetworkCredential("eulersin@gmail.com", "richard1richard");
                sc.DeliveryMethod = SmtpDeliveryMethod.Network;
                sc.Send(mm); 
            }
            catch (System.Exception ){
                return false;
            }
            mm.Dispose();
            return true;
        }

        public string GetBody( string userid, string href){
            string sRet = BaseData.GetSysBaseData(13);
            sRet = sRet.Replace("#userid#", userid);
            sRet = sRet.Replace("#href#", href);
            return sRet;
        }
    }
}

